package com.shop.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.mapper.DtsGrouponRulesMapper;
import com.shop.pojo.DtsArticle;
import com.shop.pojo.DtsGrouponRules;
import com.shop.service.DtsGrouponRulesService;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName DtsGrouponRulesServiceImpl
 * @Author xiao宋
 * @Date 13:53  2022/10/22
 * @Version 1.0
 * @Description TODO
 */
@Service
public class DtsGrouponRulesServiceImpl implements DtsGrouponRulesService {
    @Autowired
    DtsGrouponRulesMapper grouponRulesMapper;
    @Override
    public Map<String, Object> findByPage(Integer page, Integer limit, String sort, String order, Integer goodsId) {
        IPage<DtsGrouponRules> iPage = new Page<>(page, limit);
        QueryWrapper<DtsGrouponRules> w = new QueryWrapper<>();
        w.eq("deleted", false);
        if (goodsId!=null){
            w.eq("goods_id",goodsId);
        }
        //        排序方式
        if ("desc".equalsIgnoreCase(order)) {
            w.orderByDesc(sort);
        } else {
            w.orderByAsc(sort);
        }
        grouponRulesMapper.selectPage(iPage,w);
        Map<String, Object> result = new HashMap<>();
        result.put("total", iPage.getTotal());
        result.put("items", iPage.getRecords());
        return result;
    }
}
